library(dplyr)
library(magrittr)


setClass('ampseq', slots = c(
  gt = "ANY",
  metadata = "ANY",
  markers = "ANY",
  loci_performance = "ANY",
  pop_summary = "ANY",
  controls = "ANY",
  discarded_loci = "ANY",
  discarded_samples = "ANY",
  plots = "ANY"
))

load(params$RData_image)

The haplotype of each sample is stored in the table aacigar_table within the object drug_resistant_haplotypes_plot.

plot_relatedness_distribution_between$plot
**Figure 1:** IBD distribution between sites

Figure 1: IBD distribution between sites

plot_frac_highly_related_between$plot
**Figure 2:** Frequency of highly related among sites

Figure 2: Frequency of highly related among sites

if(!is.na(Variable2)){plot_frac_highly_related_overtime_between$plot_IBD_correlation_matrix}
**Figure 2:** Frequency of highly related between sites over time

Figure 2: Frequency of highly related between sites over time

if(!is.na(Variable2)){plot_frac_highly_related_overtime_between$plot_frac_highly_related}
**Figure 2:** Frequency of highly related between sites over time

Figure 2: Frequency of highly related between sites over time

IBD_PCA
**Figure 3:** IBD PCA

Figure 3: IBD PCA

plot_network(pairwise_relatedness,
                               threshold = ibd_thres,
                               metadata = ampseq_object@metadata, 
                               sample_id = 'Sample_id', 
                               group_by = Variable1, 
                               levels = levels(as.factor(ampseq_object@metadata[[Variable1]])),
                               colors = brewer.pal(n = nlevels(as.factor(ampseq_object@metadata[[Variable1]])), name = 'Accent')
                              )
**Figure 4:** IBD network

Figure 4: IBD network

## $network_object
## IGRAPH f101f9d UN-- 844 24772 -- 
## + attr: name (v/c)
## + edges from f101f9d (vertex names):
##  [1] ID00033--ID01021 ID00033--ID01031 ID00033--ID01032 ID00033--ID00052
##  [5] ID00033--ID00058 ID00033--ID00301 ID00033--ID00350 ID00033--ID01043
##  [9] ID00033--ID01044 ID00033--ID01045 ID00033--ID01047 ID00033--ID01051
## [13] ID00033--ID01058 ID00033--ID01075 ID00033--ID01080 ID00033--ID01081
## [17] ID00033--ID01113 ID00033--ID01124 ID00033--ID01125 ID00033--ID01165
## [21] ID00033--ID01168 ID00033--ID01173 ID00033--ID01126 ID00033--ID01127
## [25] ID00033--ID01134 ID00033--ID01142 ID00033--ID01149 ID00033--ID01150
## [29] ID00034--ID00039 ID00034--ID00065 ID00034--ID00089 ID00034--ID00092
## + ... omitted several edges
## 
## $plot_network
## NULL

Pairwise relatedness comparisons between categories of Variable1

plot_relatedness_distribution_between$relatedness %>%
  DT::datatable(extensions = 'Buttons',
                options = list(dom = 'Blfrtip',
                  buttons = c('csv', 'excel')))